// *****************************************************************************
// Copyright (c) 2005 - 2017 Qualcomm Technologies International, Ltd.
// %%version
//
// *****************************************************************************

#include "aac_library.h"

#ifdef AACDEC_SBR_ADDITIONS

.MODULE $aacdec;
   .DATASEGMENT DM;

   #include "sbr_qmf_stop_channel_offset_flash.asm"
   #include "sbr_log2_table_flash.asm"
   #include "sbr_huffman_tables_flash.asm"
   #include "sbr_q_div_table_flash.asm"
   #include "sbr_v_noise_table_flash.asm"
   #include "sbr_analysis_synthesis_tables.asm"


   .VAR/DMCONST sbr_est_curr_env_one_over_div_flash[] =
      1.000000000000000,  0.500000000000000,  0.333333333333333,  0.250000000000000,  0.200000000000000,
      0.166666666666667,  0.142857142857143,  0.125000000000000,  0.111111111111111,  0.100000000000000,
      0.090909090909091,  0.083333333333333,  0.076923076923077,  0.071428571428571,  0.066666666666667,
      0.062500000000000,  0.058823529411765,  0.055555555555556,  0.052631578947368,  0.050000000000000,
      0.047619047619048,  0.045454545454545,  0.043478260869565,  0.041666666666667,  0.040000000000000,
      0.038461538461538,  0.037037037037037,  0.035714285714286,  0.034482758620690,  0.033333333333333,
      0.032258064516129,  0.031250000000000,  0.030303030303030,  0.029411764705882,  0.028571428571429,
      0.027777777777778,  0.027027027027027,  0.026315789473684,  0.025641025641026,  0.025000000000000,
      0.024390243902439,  0.023809523809524,  0.023255813953488,  0.022727272727273,  0.022222222222222,
      0.021739130434783,  0.021276595744681,  0.020833333333333,  0.020408163265306,  0.020000000000000,
      0.019607843137255,  0.019230769230769,  0.018867924528302,  0.018518518518519,  0.018181818181818,
      0.017857142857143,  0.017543859649123,  0.017241379310345,  0.016949152542373,  0.016666666666667,
      0.016393442622951,  0.016129032258065,  0.015873015873016,  0.015625000000000,  0.015384615384615,
      0.015151515151515,  0.014925373134328,  0.014705882352941,  0.014492753623188,  0.014285714285714,
      0.014084507042254,  0.013888888888889,  0.013698630136986,  0.013513513513514,  0.013333333333333,
      0.013157894736842,  0.012987012987013,  0.012820512820513,  0.012658227848101,  0.012500000000000,
      0.012345679012346,  0.012195121951220,  0.012048192771084,  0.011904761904762,  0.011764705882353,
      0.011627906976744,  0.011494252873563,  0.011363636363636,  0.011235955056180,  0.011111111111111,
      0.010989010989011,  0.010869565217391,  0.010752688172043,  0.010638297872340,  0.010526315789474,
      0.010416666666667,  0.010309278350515,  0.010204081632653,  0.010101010101010,  0.010000000000000;


   /* -- SBR small constants:  pool into a single combined block for code size efficiency -- */
   .BLOCK/DMCONST sbr_small_const_arrays_flash;

      // limiter frequency table constants and variables
                     // 0.49/Q/8        Q = [1.2, 2, 3];   divide by 8 to match sbr_log_base2_table
      .VAR sbr_limiter_bands_compare_flash [] = 0.051041666666667, 0.030625, 0.020416666666667;

      .VAR sbr_phi_re_sin_flash[] = 1, 0, -1, 0;

      .VAR sbr_phi_im_sin_flash[] = 0, 1, 0, -1;

      .VAR sbr_h_smooth_flash[] =  0.03183050093751, 0.11516383427084, 0.21816949906249, 0.30150283239582,  0.33333333333333;

      .VAR sbr_goal_sb_tab_flash[] = 21, 23, 32, 43, 46, 64, 85, 93, 128, 0, 0, 0;

      .VAR SBR_log2Table_flash[] =  0, 0, 1, 2, 2, 3, 3, 3, 3, 4;

      .VAR sbr_fscale_gt_zero_temp_1_flash[]  =  12, 10, 8;
      // 1 / SBR_warp
      .VAR sbr_fscale_gt_zero_temp_2_flash[]  =  1.0, 0.76923076923077;

      // startMin Table
      .VAR sbr_startMinTable_flash[12] = 7, 7, 10, 11, 12, 16, 16, 17, 24, 32, 35, 48;

      // stopMin Table
      .VAR sbr_stopMinTable_flash[12] = 13, 15, 20, 21, 23, 32, 32, 35, 48, 64, 70, 96;

      // SBR offsetIndexTable
      .VAR sbr_offsetIndexTable_flash[9] = 5, 5, 4, 4, 4, 3, 2, 1, 0;

      .VAR sbr_E_pan_tab_flash[] =
            0.00024408100000,   0.00048804300000,   0.00097561000000,   0.00194932000000,   0.00389105000000,
            0.00775194000000,   0.01538460000000,   0.03030300000000,   0.05882350000000,   0.11111100000000,
            0.20000000000000,   0.33333300000000,   0.50000000000000,   0.66666700000000,   0.80000000000000,
            0.88888900000000,   0.94117600000000,   0.96969700000000,   0.98461500000000,   0.99224800000000,
            0.99610900000000,   0.99805100000000,   0.99902400000000,   0.99951200000000,   0.99975600000000;

      .VAR sbr_one_over_x_flash[] =
            1.000000000000000,   0.500000000000000,   0.333333333333333,   0.250000000000000,   0.200000000000000,   0.166666666666667,   0.142857142857143,   0.125000000000000,
            0.111111111111111,   0.100000000000000,   0.090909090909091,   0.083333333333333,   0.076923076923077,   0.071428571428571,   0.066666666666667,   0.062500000000000,
            0.058823529411765,   0.055555555555556,   0.052631578947368,   0.050000000000000,   0.047619047619048,   0.045454545454545,   0.043478260869565,   0.041666666666667,
            0.040000000000000,   0.038461538461538,   0.037037037037037,   0.035714285714286,   0.034482758620690,   0.033333333333333,   0.032258064516129,   0.031250000000000;

      .VAR sbr_pow2_table_flash[] =
            0.50000000000000,   0.50544464302585,   0.51094857432706,   0.51651243951061,   0.52213689121371,   0.52782258918028,
            0.53357020033841,   0.53938039887856,   0.54525386633263,   0.55119129165392,   0.55719337129795,   0.56326080930412,
            0.56939431737835,   0.57559461497649,   0.58186242938879,   0.58819849582514,   0.59460355750136,   0.60107836572635,
            0.60762367999023,   0.61424026805344,   0.62092890603674,   0.62769037851235,   0.63452547859587,   0.64143500803939,
            0.64841977732550,   0.65548060576238,   0.66261832157987,   0.66983376202665,   0.67712777346845,   0.68450121148730,
            0.69195494098192,   0.69948983626916,   0.70710678118655,   0.71480666919599,   0.72259040348852,   0.73045889709032,
            0.73841307296975,   0.74645386414563,   0.75458221379671,   0.76279907537227,   0.77110541270397,   0.77950220011892,
            0.78799042255394,   0.79657107567113,   0.80524516597463,   0.81401371092867,   0.82287773907698,   0.83183829016337,
            0.84089641525371,   0.85005317685926,   0.85930964906124,   0.86866691763685,   0.87812608018665,   0.88768824626326,
            0.89735453750155,   0.90712608775020,   0.91700404320467,   0.92698956254169,   0.93708381705515,   0.94728799079348,
            0.95760328069857,   0.96803089674615,   0.97857206208770,   0.98922801319398,   1.00000000000000;

      // SBR QMF Stop channel offset table
      .VAR sbr_qmf_stop_channel_offset_flash[12] =
            &$aacdec.sbr_qmf_stop_channel_offset_96000,
            &$aacdec.sbr_qmf_stop_channel_offset_88200,
            &$aacdec.sbr_qmf_stop_channel_offset_64000,
            &$aacdec.sbr_qmf_stop_channel_offset_48000,
            &$aacdec.sbr_qmf_stop_channel_offset_44100,
            &$aacdec.sbr_qmf_stop_channel_offset_24000_to_32000,
            &$aacdec.sbr_qmf_stop_channel_offset_24000_to_32000,
            &$aacdec.sbr_qmf_stop_channel_offset_22050,
            &$aacdec.sbr_qmf_stop_channel_offset_16000,
            &$aacdec.sbr_qmf_stop_channel_offset_12000,
            &$aacdec.sbr_qmf_stop_channel_offset_11025,
            &$aacdec.sbr_qmf_stop_channel_offset_8000;

      // SBR offset table
      .VAR sbr_offset_flash[6] =
            &$aacdec.sbr_offset_fs_sbr_16000,
            &$aacdec.sbr_offset_fs_sbr_22050,
            &$aacdec.sbr_offset_fs_sbr_24000,
            &$aacdec.sbr_offset_fs_sbr_32000,
            &$aacdec.sbr_offset_fs_sbr_44100_to_64000,
            &$aacdec.sbr_offset_fs_sbr_gt_64000;
   .ENDBLOCK;


.ENDMODULE;

#endif
